package helper.request.contacts;

import java.sql.SQLException;

import server.dbconnector.DatabaseConnector;
import helper.request.RequestUndo;
import base.Contact;
import base.User;

public class DeleteContactRequest implements ContactRequest,RequestUndo{
	private static final long serialVersionUID = 8595473366142614186L;
	private int currentuserid;
	private int targetuserid;
	private Contact contact;
	private int level;
	public DeleteContactRequest(int a,int b,Contact c){
		this.currentuserid=a;
		this.targetuserid=b;
		this.contact=c;
		this.level=c.getlevel();
	}
	public User gettargetuser() {
		return null;
	}

	@Override
	public int gettargetuserid() {
		return targetuserid;
	}

	@Override
	public User getcurrentuser() {
		return null;
	}

	@Override
	public int getcurrentuserid() {
		return currentuserid;
	}

	@Override
	public boolean execute() {
		contact.setlevel(-1);
		return true;
	}
	public String toString(){
		return "您删除了好友"+contact.gettargetuser().getrealname();
	}
	@Override
	public void process(DatabaseConnector dc)throws SQLException{
		dc.commit("delete from contact where userIDFrom="+currentuserid+" and userIDTo="+targetuserid);
		System.out.println("aaa"+currentuserid+" "+targetuserid);
		dc.commit("delete from contact where userIDFrom="+targetuserid+" and userIDTo="+currentuserid);
		
	}
	@Override
	public boolean de_execute() {
		contact.setlevel(level);
		return true;
	}
}

